/* 

THIS DOFILE PRODUCES SEVERAL TABLES AND FIGURES FROM:

"Regulation by Reputation? Intermediaries, Labor Abuses, and International Migration" 
- A. Nilesh Fernando (University of Notre Dame); corresponding author (nilesh.fernando@nd.edu)  
- Niharika Singh (University of Notre Dame) 

See readme.docx for details 

*/ 

clear all
set matsize 1000
set more off 
#delimit;

* Set directory; 

cd "~/Desktop/migrec_replication/do/";

use ../dta_secure/5_firm_mn_final.dta, replace;

*------------------------------------------------------------*
* TABLE 1: AGENCY-MONTH LEVEL SUMMARY STATISTICS, 2005-2015  * 
*------------------------------------------------------------;

clear results; 
clear matrix; 
clear mata;
estimates clear; 
	eststo clear;
	
	estpost tabstat migrant women domestic_worker saudi mean_salary_d_win 
		num_job_orders_win num_vac_req complaints comp_int_m solved_rate_m solved_months_m if comp_opt == 1 , 
		stat(mean sd med  n) col(stat);
	
	
	esttab using ../out/table1.tex,
		cells("mean(label(Mean) fmt(2)) sd(label(SD) fmt(2))
		p50(label(Median) fmt(2)) 
		 count(label(N) fmt(0))") 
		label nonum noobs 
		replace;

*------------------------------------------------------------*
* TABLE 2: INVESTMENT IN RATING CRITERIA AND MARKET OUTCOMES * 
*------------------------------------------------------------;

* Panel A: Effects by Program Phase; 

eststo clear;

		
		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
			
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0
		 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1   , cluster(agency_id) 
		absorb(agency_id  month_year##c.qs_0508_bin);
		
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1   , cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin);
			
		sum num_job_orders_win if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009; ; 
		estadd scalar ymean = r(mean);
		
	
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/market_a.tex", b(%12.3f) se(%12.3f)
		keep(elig_firm_postmp_2009 elig_firm_postm) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" ) mtitles
		nonotes nonumber 	;

*Panel B: Effects by Agency Quality;  

eststo clear;


		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		high_elig_postm_2009 low_elig_postm_2009    
		low_postmp_2009 high_postmp_2009  
		
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
		
	
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009     
		if comp_opt == 1  , cluster(agency_id)
		absorb(agency_id month_year );
		  
			
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		if comp_opt == 1   , cluster(agency_id) 
		
		absorb(agency_id month_year##c.migrants_0508_bin );
		 
			
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 

		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ; 
		estadd scalar ymean = r(mean);
				
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/market_b.tex", b(%12.3f) se(%12.3f) 
		keep(high_elig_postm_2009 low_elig_postm_2009)
		
		stats(N ymean,  label("N" "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 
		"Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber;
		

*Panel C: Effects by Agency Quality and Program Phase;  

eststo clear;

		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		    );
		
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Migrants"): reghdfe migrant
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1  , cluster(agency_id)
		 absorb(agency_id month_year);
		
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
			

		eststo, title("Job Orders"): reghdfe num_job_orders_win
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
			
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		 
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);
				
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/market_c.tex", b(%12.3f) se(%12.3f) 
		keep(high_elig_postmp_2009 low_elig_postmp_2009 high_elig_postm
		low_elig_postm)
	
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postmp_2009 "Elig*High*2010-12"
		 low_elig_postmp_2009 
		"Elig*Low*2010-12" high_elig_postm "Elig*High*2012-15"
		 low_elig_postm "Elig*Low*2012-15"  
		)  mtitles
		nonotes nonumber 	;	


*------------------------------*
* TABLE 3: PLACEMENT QUALITY   * 
*------------------------------;

* Panel A: Effects by Program Phase; 

eststo clear;

		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win 
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin    );
		
		sum mean_salary_win if comp_opt == 1
		 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Contract Renewal"): reghdfe renew_emp_or_self_share 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1 & firm_exit_1yr != 1,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin 
		  );

		sum renew_emp_or_self_share if comp_opt == 1 
		& elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
			
		eststo, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin month_year##c.qs_0508_bin    );
			
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 
		& elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Contract Quality"): reghdfe jo_quality 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin   );
		
		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
			

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/placement_a.tex", b(%12.3f)
		 se(%12.3f) keep(elig_firm_postmp_2009 elig_firm_postm)
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;
	

*Panel B: Effects by Agency Quality; 


eststo clear;

		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		 month_year##c.migrants_0508_bin       );
		 		
		sum mean_salary_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean) ;

						
		eststo , title("Contract Renewal"): reghdfe renew_emp_or_self_share
		high_elig_postm_2009 low_elig_postm_2009    
		high_postmp_2009 low_postmp_2009
		
		if comp_opt == 1 & firm_exit_1yr != 1 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
	
		sum renew_emp_or_self_share if comp_opt == 1 & elig_firm == 0 
		& year < 2010  ; 
		estadd scalar ymean = r(mean) ;
		

		eststo m3, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009 
		
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin       );
		
			
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 
		& year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Contract Quality"): reghdfe jo_quality 
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin      );
		
		
		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean) ;
		

		esttab * using "../out/placement_b.tex", b(%12.3f) se(%12.3f) 
		keep(high_elig_postm_2009 low_elig_postm_2009)
		stats(N ymean,  label("N" "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 
		"Elig*Low*Post-2010") 
		 mtitles
		nonotes nonumber;
	

*Panel C: Effects by Agency Quality and Program Phase;  

eststo clear;


		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm

		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		 month_year##c.migrants_0508_bin       );
		
		sum mean_salary_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
			
		
		eststo, title("Contract Renewal"): reghdfe renew_emp_or_self_share 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 
		low_postmp_2009 
		
		if comp_opt == 1 & firm_exit_1yr != 1,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		      );

		sum renew_emp_or_self_share if comp_opt == 1  & elig_firm == 0
		 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		

		eststo, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		   
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin       );
			
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 
		& year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Contract Quality"): reghdfe jo_quality
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		    
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin      );
		
		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/placement_c.tex", b(%12.3f) se(%12.3f) 
		keep(high_elig_postmp_2009 low_elig_postmp_2009 high_elig_postm    
		low_elig_postm)
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postmp_2009 "Elig*High*2010-12"
		 low_elig_postmp_2009 
		"Elig*Low*2010-12" high_elig_postm "Elig*High*2012-15"
		 low_elig_postm "Elig*Low*2012-15"  
		) mtitles
		nonotes nonumber ;
		
*-------------------------------*
* TABLE 5: SPILLOVER EFFECTS    * 
*-------------------------------;
		
		eststo clear;
					
		eststo, title("Migrants"): reghdfe migrant
		any_elig_100ft_postm_2009     
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_100ft_postm_2009     
		if comp_opt == 1 & elig_firm == 0, clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  comp_opt == 1 & elig_firm == 0 & 
		any_elig_100ft_postm_2009 == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_100ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_100ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);


		estadd scalar ar=e(r2_a);
	

	esttab using "../out/spillovers.tex", b(%12.3f) se(%12.3f)
	 keep(any_elig_100ft_postm_2009) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(any_elig_100ft_postm_2009 "Any Elig*Post-2010"  ) mtitles
		nonotes nonumber 	;




****************************************************************************************
********************************* ONLINE APPENDIX               * **********************
****************************************************************************************;

*----------------------------------*
* APPENDIX A4: COMPLAINT TYPES     *
*----------------------------------*;
preserve; 

use ../dta_secure/complaints_a.dta, clear;

	gen complaints = 1;
	
	keep problem_desc complaints;
	
	bys problem_desc: egen cmpl_type = sum(complaints);
	egen total_cmpl = sum(complaints);
	bys problem_desc: gen pct = cmpl_type / total_cmpl;
	replace pct = pct*100;
	
	replace problem_desc = "Not Sent Back After Completion of Contract Period" if problem_desc == "Not Sent Back After Completion of Conract Period";

	label var cmpl_type "Complaints";
	label var pct "Percentage of Total Complaints";
	
	keep if cmpl_type >= 2849;
		
	gen problem = problem_desc;
	egen group = group(cmpl_type problem_desc);
	replace group = -group;
	labmask group, values(problem);
	label var group "problem";
	
	format pct %9.2f;
	
	eststo clear;
	estpost tabstat cmpl_type pct, by(group) stat(max) col(var) nototal;
	
	esttab using ../out/complaints_sumstats.tex, replace cells("cmpl_type(label(Complaints)) pct(fmt(2) 
		label(Percentage of Total Complaints))") nostar noobs 
		nonote nomtitle nonumber varlabels(`e(labels)');		
			
restore;

*----------------------------------------------*
* APPENDIX A18: INVESTMENT IN THE AUDIT SCORE  * 
*----------------------------------------------*;

capture file close tableTex ; 
macro drop _all            ;

local OUT   "../out/audit_invest.tex" ;


local BASE "year==2015 & month==12 & elig_firm==1 & comp_opt==1" ;

local buckets 4 5 6 7 8 9 ;

local collabs `" "4" "5" "6" "7" "8" "9" "High" "Low" "' ;

local rowvars quality_control_11  rp_partial_audit_marks 
              record_keeping marketing staff other 
              performance_rate star_level ;

local rowlabs  `" "Quantitative Score (2011)"
                 "Audit Score"
                 "Record-Keeping"
                 "Marketing"
                 "Staff"
                 "Other"
                 "Combined Score"
                 "Stars" "' ;

file open tableTex using "`OUT'", write replace text ;
file write tableTex "{" _n ;
file write tableTex "\begin{tabular}{l*{8}{c}}" _n ;
file write tableTex "\toprule" _n ;

file write tableTex 
    "& \multicolumn{6}{c}{Low Quality Agencies by 2009 Quantitative Score} &" 
    " \multicolumn{2}{c}{\quad} \\" _n ;
file write tableTex 
    "& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\" _n ;
file write tableTex 
    "& 4 & 5 & 6 & 7 & 8 & 9 & High & Low \\" _n ;
file write tableTex "\midrule" _n ;


local r = 1 ;
foreach v of local rowvars { ;                
    local lab : word `r' of `rowlabs';
    local lab = subinstr("`lab'","""","",.);
    file write tableTex "`lab'";

    foreach b of local buckets {;
        quietly summarize `v' if `BASE' & low_score==1 & quality_control_09==`b';
        local m : display %4.1f round(r(mean),0.1);
        file write tableTex " & `m'";
    };

    quietly summarize `v' if `BASE' & low_score==0;
            local n : display %4.1f round(r(mean),0.1);

    file write tableTex " & `n'";
    
    quietly summarize `v' if `BASE' & low_score==1;
    
            local o : display %4.1f round(r(mean),0.1);

    file write tableTex " &  `o'";

    file write tableTex "\\" _n      ;
    local ++r;
} ;                                      

file write tableTex "N(Agency Exit)";
foreach b of local buckets {;
    distinct agency_id if `BASE' & low_score==1 & quality_control_09==`b' & firm_exit_1yr == 1 ;
    file write tableTex " &  `r(ndistinct)'";
};

distinct agency_id if `BASE' & low_score==0  & firm_exit_1yr == 1;
file write tableTex " &  `r(ndistinct)'";
distinct agency_id if `BASE' & low_score==1  & firm_exit_1yr == 1;
file write tableTex " &  `r(ndistinct)'  \\" _n;

file write tableTex "N";
foreach b of local buckets {;
    quietly count if `BASE' & low_score==1 & quality_control_09==`b';
    file write tableTex " &  `r(N)'";
};
quietly count if `BASE' & low_score==0;
file write tableTex " &  `r(N)'";
quietly count if `BASE' & low_score==1;
file write tableTex " &  `r(N)'  \\" _n;

file write tableTex " \\" _n;
file write tableTex "\bottomrule" _n;
file write tableTex "\end{tabular}" _n;
file write tableTex "}" _n;
file close tableTex ;

*----------------------------------------------*
* APPENDIX A19: AGENCY EXIT OVER TIME          * 
*----------------------------------------------*;

***PART 1. First figure out agency exit by quality between 2005 & 2009;
** STEP 1: collapse necessary variables ; 

preserve; 

collapse (sum) migrant (max) firm_exit_1yr low_score (first) elig_firm  partial_qual_marks comp_opt_09, by(agency_id year) ;

gen migrant_05_tmp = migrant if year == 2005 ; 

bysort agency_id: egen migrant_05 = max(migrant_05_tmp); 
drop migrant_05_tmp;

gen migrant_09_tmp = migrant if year == 2009 ; 

bysort agency_id: egen migrant_09 = max(migrant_09_tmp); 
drop migrant_09_tmp;

** PART 2. figure out quality in 2005; 

gen quality_rating_05_tmp = partial_qual_marks if year == 2005; 
gen quality_rating_09_tmp = partial_qual_marks if year == 2009; 

bysort agency_id: egen quality_rating_05 = max(quality_rating_05_tmp); 
bysort agency_id: egen quality_rating_09 = max(quality_rating_09_tmp); 


gen elig_firm_05 = (migrant_05 >= 100);

sum quality_rating_05 if year == 2005 & migrant_05 > 0, det; 

gen low_score_05 = ( quality_rating_05 < `r(p50)');  

gen comp_opt_05 = (migrant_05 >= 45 & migrant_05 <= 155); 

sum quality_rating_09 if year == 2009 & migrant_09 > 01, det; 

gen low_score_09 = ( quality_rating_09 < `r(p50)');  

*  (1)  Pre-period 2005-09 ; 

sum firm_exit_1yr if year==2015 & migrant_05>0 & comp_opt_05==1 & low_score_05==0 ;
scalar high_pre = r(mean)*100 ;
sum firm_exit_1yr if year==2015 & migrant_05>0 & comp_opt_05==1 & low_score_05==1 ;
scalar low_pre  = r(mean)*100 ;
count  if year==2009 & migrant_05>0 & comp_opt_05==1 ;
scalar N_pre    = r(N) ;


*  (2)  Post-period 2010-15 ; 
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==0 ;
scalar high_post = r(mean)*100 ;
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==1 ;
scalar low_post  = r(mean)*100 ;
count  if year==2015 & migrant_09>0 & comp_opt_09==1 ;
scalar N_post    = r(N) ;

*  (3)  Post 2010-15, **Eligible** firms only  ;
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==0 & elig_firm==1 ;
scalar high_elig = r(mean)*100 ;
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==1 & elig_firm==1 ;
scalar low_elig  = r(mean)*100 ;
count  if year==2015 & migrant_09>0 & comp_opt_09==1 & elig_firm==1 ;
scalar N_elig    = r(N) ;

*  (4)  Post 2010-15, **Comparison** firms only   ;
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==0 & elig_firm==0 ;
scalar high_comp = r(mean)*100 ;
sum firm_exit_1yr if year==2015 & migrant_09>0 & comp_opt_09==1 & low_score==1 & elig_firm==0 ;
scalar low_comp  = r(mean)*100 ;
count  if year==2015 & migrant_09>0 & comp_opt_09==1 & elig_firm==0 ;
scalar N_comp    = r(N) ;

matrix R = (  high_pre , high_post , high_elig , high_comp \   // High %
              low_pre  , low_post  , low_elig  , low_comp  \   // Low  %
              N_pre    , N_post    , N_elig    , N_comp    ) ; // counts

matrix rownames R = "High" "Low" "N" ;
matrix colnames R = "(1)" "(2)" "(3)" "(4)" ;


esttab matrix(R, fmt(%4.1f)) using "../out/firm_exit.tex", replace  ///
        booktabs nomtitles nonumber                                 ///
        collabels("Pre(2005--09)"                                   ///
                  "Post(2010--15)"                                   ///
                  "Post(2010--15)"                         ///
                  "Post(2010--15)") ;
restore; 

*----------------------------------------------*
* APPENDIX B1: RESULTS FROM AGENCY SURVEY  * 
*----------------------------------------------*;

preserve; 

use ../dta_secure/agency_survey_clean.dta, clear; 


* Panel A: Employer Reputation ; 
capture file close pana;
local outfile "../out/agency_survey_a.tex" ;
local vars   q74_1 q74_2 q74_3 q74_4 q74_5 ;
local labels `" "Check if Blacklisted" "Consult Other Agencies" 
"Consult Returned Migrants" "Contact SL Consulate" "Contact SLBFE" "' ;

quietly count ;
local N_total = r(N) ;

file open pana using "`outfile'", write replace text ;
file write pana "{" _n            ;
file write pana "\begin{tabular}{lcc}"  _n                      ;
file write pana "\toprule"                _n                   ;
file write pana "Source & N (1) & Percent (2) \\"   _n         ;
file write pana "\midrule"                             _n      ;


local i = 1 ;
foreach v of varlist `vars' { ;
    quietly count if `v' != . ;
    local n   = r(N) ;
    local pct = round(100*`n'/`N_total',1) ; 
    local lab : word `i' of `labels' ;
    file write pana "`lab' & `n' & `pct' \% \\ " _n ;
    local ++i ;
} ;

file write pana "\bottomrule" _n ;
file write pana "\end{tabular}" _n ;
file write pana "}" _n  ;
file close pana ;

* Panel B Reasons for Rejecting a Job Order; 

macro drop _all;   
capture file close panb;
local outfile "../out/agency_survey_b.tex" ;
local vars  q72b_1 q72b_2 q72b_3 q72b_4 q72b_5 q72b_6 ;
local labels `" "Job Wasn’t Safe" "Employer Reputation" 
"Foreign Agent Reputation" "Too Many Amenities" "Low Commission"
"Hard to find Workers" "' ;

quietly count if q72a == 1;
local N_total = r(N) ;

file open panb using "`outfile'", write replace text ;
file write panb "{" _n            ;
file write panb "\begin{tabular}{lcc}"  _n                      ;
file write panb "\toprule"                _n                   ;
file write panb "Source & N (1) & Percent (2) \\"   _n         ;
file write panb "\midrule"                             _n      ;

local i = 1 ;
foreach v of varlist `vars' { ;
    quietly count if `v' != . ;
    local n   = r(N) ;
    local pct = round(100*`n'/`N_total',1) ; 
    local lab : word `i' of `labels' ;
    file write panb "`lab' & `n' & `pct' \% \\" _n ;
    local ++i ;
} ;

file write panb "\bottomrule" _n ;
file write panb "\end{tabular}" _n ;
file write panb "}" _n  ;
file close panb ;
restore;

*----------------------------------------------*
* APPENDIX B2: CHARACTERISTICS OF JOB ORDERS   * 
*----------------------------------------------*;

* Panel A: Effects by Program Phase; 

eststo clear;

		eststo, title("\# Employers"): reghdfe num_employers 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum num_employers if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("\# New Employers"): reghdfe new_employer
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum new_employer if comp_opt == 1 & elig_firm == 0 & year >= 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("\# Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Good Orders (\%)"): reghdfe num_jo_good_emp_pre2009_25_s_m 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\# Bad Orders"): reghdfe num_jo_bad_emp_pre2009_25 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum num_jo_bad_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Bad Orders (\%)"): reghdfe num_jo_bad_emp_pre2009_25_s_m 
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum num_jo_bad_emp_pre2009_25_s_m if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/joborder_a.tex", b(%12.4f) se(%12.3f) keep(     
		  	elig_firm_postmp_2009 elig_firm_postm         ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber 	;


*Panel B: Effects by Agency Quality; 

eststo clear;

		eststo, title("\# Employers"): reghdfe num_employers 
		high_elig_postm_2009 low_elig_postm_2009  
		low_postm_2009 high_postm_2009  
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_employers if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\# New Employers"): reghdfe new_employer
			high_elig_postm_2009 low_elig_postm_2009
			  low_postm_2009 high_postm_2009    
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum new_employer if comp_opt == 1 & elig_firm == 0 & year >= 2010; 
		estadd scalar ymean = r(mean);
		
			
		eststo, title("\# Good Orders"): reghdfe num_jo_good_emp_pre2009_25
		high_elig_postm_2009 low_elig_postm_2009  
		low_postm_2009 high_postm_2009  
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
				
		eststo, title("Good Share(\%)"): reghdfe num_jo_good_emp_pre2009_25_s_m 
		high_elig_postm_2009 low_elig_postm_2009  
		low_postm_2009 high_postm_2009  
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_good_emp_pre2009_25_s_m if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
					
		eststo, title("\# Bad Orders"): reghdfe num_jo_bad_emp_pre2009_25
		high_elig_postm_2009 low_elig_postm_2009  
		low_postm_2009 high_postm_2009  
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_bad_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
				
		eststo, title("Bad Share(\%)"): reghdfe num_jo_bad_emp_pre2009_25_s_m 
		high_elig_postm_2009 low_elig_postm_2009  
		low_postm_2009 high_postm_2009  
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_bad_emp_pre2009_25_s_m if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/joborder_b.tex", b(%12.4f) se(%12.3f) keep(     
			high_elig_postm_2009 low_elig_postm_2009       ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010"
		 low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber ;
	
		
*Panel C: Effects by Agency Quality and Program Phase;  

eststo clear;

		eststo, title("\# Employers"): reghdfe num_employers 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_employers if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\# New Employers"): reghdfe new_employer
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1  &  firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum new_employer if comp_opt == 1 & elig_firm == 0 & year >= 2010; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("\# Good Orders"): reghdfe num_jo_good_emp_pre2009_25
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Good Share(\%)"): reghdfe num_jo_good_emp_pre2009_25_s_m 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_good_emp_pre2009_25_s_m if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\# Bad Orders"): reghdfe num_jo_bad_emp_pre2009_25
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_bad_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
				
		eststo, title("Bad Share(\%)"): reghdfe num_jo_bad_emp_pre2009_25_s_m 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 &  firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin   );
		
		sum num_jo_bad_emp_pre2009_25_s_m if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/joborder_c.tex", b(%12.4f) se(%12.3f) 	keep(     
			high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postmp_2009 "Elig*High*2010-12"
		 low_elig_postmp_2009 
		"Elig*Low*2010-12" high_elig_postm "Elig*High*2012-15"
		 low_elig_postm "Elig*Low*2012-15"  
		) mtitles
		nonotes nonumber 	;
		

*-------------------------------------------------*
* APPENDIX B3: COMPONENTS OF CONTRACT QUALITY     * 
*-------------------------------------------------*;

* Panel A: Effects by Program Phase; 

eststo clear;

		eststo, title("Return Ticket"): reghdfe ticket_share_vac 
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum ticket_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Health Insurance"): reghdfe med_share_vac
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum med_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Accommodation"): reghdfe accom_share_vac
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin  month_year##c.qs_0508_bin  );
		
		sum accom_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
					
		eststo, title("Food"): reghdfe food_share_vac 
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1 & firm_exit_1yr != 1 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
		 
		sum food_share_vac if comp_opt == 1  ; 
		estadd scalar ymean = r(mean);
			
		eststo, title("Avg. Salary (USD)"): reghdfe usd_minsalary_d 
		elig_firm_postmp_2009 elig_firm_postm  
		if comp_opt == 1 & firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum usd_minsalary_d if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
			
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/quality_components_a.tex", b(%12.4f)
		 se(%12.3f) keep(
		 elig_firm_postmp_2009 elig_firm_postm      
		    ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;


*Panel B: Effects by Agency Quality; 

eststo clear;

		eststo, title("Return Ticket"): reghdfe ticket_share_vac 
		high_elig_postm_2009 low_elig_postm_2009  low_postm_2009 
		high_postm_2009    
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin     );
		
		sum ticket_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Health Insurance Orders"): reghdfe med_share_vac 
		high_elig_postm_2009 low_elig_postm_2009  low_postm_2009
		 high_postm_2009  
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin     );
			
		sum med_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Accommodation"): reghdfe accom_share_vac
		 high_elig_postm_2009 low_elig_postm_2009  low_postm_2009
		  high_postm_2009   
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin       );
		
		sum accom_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
			
					
		eststo, title("Food"): reghdfe food_share_vac
		 high_elig_postm_2009 low_elig_postm_2009  low_postm_2009 
		 high_postm_2009    
		if comp_opt == 1  & firm_exit_1yr != 1 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		     );

		sum food_share_vac if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Avg. Salary (USD)"): reghdfe usd_minsalary_d 
		high_elig_postm_2009 low_elig_postm_2009  low_postm_2009
		 high_postm_2009   

		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin     );
		
		sum usd_minsalary_d if comp_opt == 1 ; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/quality_components_b.tex", b(%12.4f) 
		se(%12.3f) keep(     
		  high_elig_postm_2009 low_elig_postm_2009       ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber;
		
	
*---------------------------------------------------*
* APPENDIX B4: COMPOSITION OF MIGRANTS RECRUITED    * 
*---------------------------------------------------*;

* Panel A: Effects by Program Phase; 

eststo clear;

		eststo, title("\% Female"): reghdfe mig_share_women 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		month_year##c.qs_0508_bin );
	

		sum mig_share_women if comp_opt == 1 & elig_firm == 0
		 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\% Pre-Complainants"): reghdfe pre_complainants_share 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum pre_complainants_share if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("\% Under 30"): reghdfe age1_share 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
		 
		
		sum age1_share if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("\% Over 50"): reghdfe age4_share
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum age4_share if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("\% Saudi"): reghdfe mig_share_saudi 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum mig_share_saudi if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/migrantcomp_a.tex",
		 b(%12.4f) se(%12.3f) keep(elig_firm_postmp_2009 elig_firm_postm) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;
	
* Panel B:  Effects by Agency Quality; 

eststo clear;

		eststo, title("\% Female"): reghdfe mig_share_women 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum mig_share_women if comp_opt == 1 & elig_firm == 0
		 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\% Pre-Complainants"): reghdfe pre_complainants_share 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		    );
	
		sum pre_complainants_share if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("\% Under 30"): reghdfe age1_share 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		    );
		 
		sum age1_share if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("\% Over 50"): reghdfe age4_share
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		    );
	
		sum age4_share if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);

		eststo, title("\% Saudi"): reghdfe mig_share_saudi 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		    );
	
		sum mig_share_saudi if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/migrantcomp_b.tex",
		 b(%12.4f) se(%12.3f) keep(	high_elig_postm_2009 low_elig_postm_2009        
		      ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber 	;


*------------------------------------------------*
* APPENDIX B6: COMPONENTS OF QUANTITATIVE SCORE  * 
*------------------------------------------------*;

* Panel A: Effects by Program Phase; 

eststo clear;

		eststo, title("Professional"): reghdfe manlev_professional 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1   , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		month_year##c.qs_0508_bin );
	

		sum manlev_professional if comp_opt == 1 & elig_firm == 0
		 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Clerical"): reghdfe manlev_clerical 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_clerical if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Middle"): reghdfe manlev_middle
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_middle if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Skilled"): reghdfe manlev_skilled 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_skilled if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Semi-Skilled"): reghdfe manlev_semiskill 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_semiskill if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Driver/Operator"): reghdfe manlev_unskilled 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_unskilled if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Domestic Work"): reghdfe manlev_dw 
		elig_firm_postmp_2009 elig_firm_postm  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
	

		sum manlev_dw if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Solve Rate"): reghdfe solved_rate 
		elig_firm_postmp_2009 elig_firm_postm
		  
		if comp_opt == 1  & migrant > 0  & filed_complaints > 0
		   ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );


		sum solved_rate if comp_opt == 1  & migrant > 0
		 & filed_complaints > 0 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/reputations_a.tex",
		 b(%12.4f) se(%12.3f) keep( elig_firm_postmp_2009 elig_firm_postm    
		      ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;

*Panel B: Effects by Agency Quality; 

eststo clear;


		eststo, title("Professional"): reghdfe manlev_professional 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	

		sum manlev_professional if comp_opt == 1 &
		 elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Middle"): reghdfe manlev_middle 
		high_elig_postm_2009 low_elig_postm_2009 
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	

		sum manlev_middle if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		
		eststo, title("Clerical"): reghdfe manlev_clerical 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	

		sum manlev_clerical if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Skilled"): reghdfe manlev_skilled 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		  );
	

		sum manlev_skilled if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Semi-Skilled"): reghdfe manlev_semiskill 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	

		sum manlev_semiskill if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Driver/Operator"): reghdfe manlev_unskilled 
		high_elig_postm_2009 low_elig_postm_2009 
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	

		sum manlev_unskilled if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Domestic Work"): reghdfe manlev_dw 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009  
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		  );
	

		sum manlev_dw if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Solve Rate"): reghdfe solved_rate 
		high_elig_postm_2009 low_elig_postm_2009
		low_postm_2009 high_postm_2009
		  
		if comp_opt == 1  & migrant > 0  & filed_complaints > 0 
		 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		  );


		sum solved_rate if comp_opt == 1  & migrant > 0 &
		 filed_complaints > 0  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/reputations_b.tex",
		 b(%12.4f) se(%12.3f) keep(	high_elig_postm_2009 low_elig_postm_2009) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber ;


*Panel C: Effects by Agency Quality and Program Phase;  

eststo clear;

		eststo, title("Professional"): reghdfe manlev_professional 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum manlev_professional if comp_opt == 1 &
		 elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Middle"): reghdfe manlev_middle 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum manlev_middle if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Clerical"): reghdfe manlev_clerical 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum manlev_clerical if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Skilled"): reghdfe manlev_skilled 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		  );
	
		sum manlev_skilled if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Semi-Skilled"): reghdfe manlev_semiskill 
			high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum manlev_semiskill if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);


		eststo, title("Driver/Operator"): reghdfe manlev_unskilled 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		   );
	
		sum manlev_unskilled if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Domestic Work"): reghdfe manlev_dw 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		  );
	

		sum manlev_dw if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);

		eststo, title("Solve Rate"): reghdfe solved_rate 
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		  
		if comp_opt == 1  & migrant > 0  & filed_complaints > 0 
		 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		  );


		sum solved_rate if comp_opt == 1  & migrant > 0 &
		 filed_complaints > 0  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/reputations_c.tex",
		 b(%12.4f) se(%12.3f) keep( 	high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm     ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
			coeflabel(high_elig_postmp_2009 "Elig*High*2010-12"
		 low_elig_postmp_2009 
		"Elig*Low*2010-12" high_elig_postm "Elig*High*2012-15"
		 low_elig_postm "Elig*Low*2012-15"  
		) mtitles
		nonotes nonumber;


*---------------------------------------------------------------*
* APPENDIX B9: HETEROGENEOUS EFFECTS FOR LOW QUALITY AGENCIES   * 
*---------------------------------------------------------------*;

** Panel A: BY AGENCY EXPERIENCE ;

eststo clear;


		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
	    elig_firm_postm_2009 age_09_ef_postm_09    
		age_09_postm_09  age_09_elig  
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postm_2009 age_09_ef_postm_09    
		age_09_postm_09  age_09_elig      
		if comp_opt == 1 & low_score == 1  , 
		cluster(agency_id)
		absorb(agency_id month_year);
		  
			
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postm_2009 age_09_ef_postm_09    
		age_09_postm_09 age_09_elig   
		if comp_opt == 1  & low_score == 1  , 
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
		
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 
		& low_score == 1; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postm_2009 age_09_ef_postm_09    
		age_09_postm_09 age_09_elig   
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
		 	
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009
		& low_score == 1 ; 
		estadd scalar ymean = r(mean);
		

		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/low_het_age_1.tex", b(%12.4f) se(%12.3f)
		keep(elig_firm_postm_2009 age_09_ef_postm_09) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel( elig_firm_postm_2009 "Elig*Post-2010" age_09_ef_postm_09 
		"Age*Elig*Post-2010") mtitles nonotes nonumber ;
		

** Panel B: BY AGENCY DENSITY; 

eststo clear;


		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		elig_firm_postm_2009 density_ef_postm_09    
		density_postm_09  density_elig  
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
	    elig_firm_postm_2009 density_ef_postm_09    
		density_postm_09  density_elig      
		if comp_opt == 1 & low_score == 1  , 
		cluster(agency_id)
		absorb(agency_id month_year);
		  
			
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		 elig_firm_postm_2009 density_ef_postm_09    
		density_postm_09 density_elig   
		if comp_opt == 1  & low_score == 1  , 
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
		
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 
		& low_score == 1; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postm_2009 density_ef_postm_09    
		density_postm_09 density_elig   
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
		 	
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009
		& low_score == 1 ; 
		estadd scalar ymean = r(mean);
		

	
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/low_het_density_1.tex", b(%12.4f) se(%12.3f)
		keep(elig_firm_postm_2009 density_ef_postm_09) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel( elig_firm_postm_2009 "Elig*Post-2010" density_ef_postm_09 
		"Density*Elig*Post-2010") mtitles nonotes nonumber ;

** Panel C:  BY GOOD ORDERS; 

eststo clear;


		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		elig_firm_postm_2009 pre_good_ef_postm_09    
		pre_good_postm_09  pre_good_elig  
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postm_2009 pre_good_ef_postm_09    
		pre_good_postm_09  pre_good_elig      
		if comp_opt == 1 & low_score == 1  , 
		cluster(agency_id)
		absorb(agency_id month_year);
		  
			
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010
		& low_score == 1; 
		estadd scalar ymean = r(mean);
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postm_2009 pre_good_ef_postm_09    
		pre_good_postm_09 pre_good_elig   
		if comp_opt == 1  & low_score == 1  , 
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 
		
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 
		& low_score == 1; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postm_2009 pre_good_ef_postm_09    
		pre_good_postm_09 pre_good_elig   
		
		if comp_opt == 1  & low_score == 1 ,
		cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		 	
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009
		& low_score == 1 ; 
		estadd scalar ymean = r(mean);
		

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/low_het_good_1.tex", b(%12.4f) se(%12.3f)
		keep(elig_firm_postm_2009 pre_good_ef_postm_09) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel( elig_firm_postm_2009 "Elig*Post-2010" pre_good_ef_postm_09 
		"Good*Elig*Post-2010") mtitles nonotes nonumber ;


*---------------------------------------------- -*
* APPENDIX B10: SPILLOVERS AND ETHNIC NETWORKS   * 
*------------------------------------------------*;


** PANEL A  ---- 100ft ;

gen sample_e = (comp_opt == 1 & elig_firm == 0 & Ethnicity != "");

		eststo clear;
			
		eststo, title("Migrants"): reghdfe migrant
		any_elig_100ft_postm_2009 any_elig_100ft_e_postm_2009     
		if  sample_e == 1  , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if sample_e == 1 & any_elig_100ft == 0 &   
 		 year < 2010  ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_100ft_postm_2009 any_elig_100ft_e_postm_2009         
		if sample_e == 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if sample_e == 1 &  
		any_elig_100ft_postm_2009 == 0 & year > 2009 ;
		
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_100ft_postm_2009 any_elig_100ft_e_postm_2009        
		if  sample_e == 1  , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  sample_e  == 1 & any_elig_100ft == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
	
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_100ft_postm_2009 any_elig_100ft_e_postm_2009        
		if  sample_e == 1 &  firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if sample_e  == 1 & any_elig_100ft == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);

		estadd scalar ar=e(r2_a);
		 

	esttab using "../out/spillover_ethnic_1.tex", nocon b(%12.4f) se(%12.3f) 
	keep( any_elig_100ft_postm_2009 any_elig_100ft_e_postm_2009 ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label 
		coeflabel(any_elig_100ft_postm_2009 "Any Elig*Post-2010" any_elig_100ft_e_postm_2009  "Co-Ethnic*Post-2010" ) mtitles
		nonotes nonumber;

** PANEL B  ---- 500ft ;

		eststo clear;
			
		eststo, title("Migrants"): reghdfe migrant
		any_elig_500ft_postm_2009 any_elig_500ft_e_postm_2009         
		if  sample_e == 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  sample_e == 1 & any_elig_500ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_500ft_postm_2009 any_elig_500ft_e_postm_2009         
		if sample_e == 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  sample_e == 1 & 
		any_elig_500ft_postm_2009  == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_500ft_postm_2009 any_elig_500ft_e_postm_2009        
		if  sample_e == 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  sample_e == 1 & any_elig_500ft == 0 &   
  		year < 2010  ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_500ft_postm_2009 any_elig_500ft_e_postm_2009        
		if  sample_e == 1 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if sample_e == 1 & any_elig_500ft == 0 &   
 		 year < 2010  ;
		estadd scalar ymean = r(mean);


		estadd scalar ar=e(r2_a);
		 

	esttab using "../out/spillover_ethnic_2.tex", nocon b(%12.4f) se(%12.3f) 
	keep(  any_elig_500ft_postm_2009 any_elig_500ft_e_postm_2009) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label 
		coeflabel(any_elig_500ft_postm_2009 "Any Elig*Post-2010" any_elig_500ft_e_postm_2009 "Co-Ethnic*Post-2010" ) mtitles
		nonotes nonumber ;


** PANEL C  ---- 0.5 km ;

		eststo clear;
			
		eststo, title("Migrants"): reghdfe migrant
		any_elig_halfkm_postm_2009 any_elig_halfkm_e_postm_2009     
		if  sample_e == 1  , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  sample_e == 1  & any_elig_halfkm == 0 &   
 		 year < 2010  ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_halfkm_postm_2009 any_elig_halfkm_e_postm_2009     
		if sample_e == 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  sample_e == 1  & 
		any_elig_halfkm_postm_2009  == 0 & year > 2009  ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_halfkm_postm_2009 any_elig_halfkm_e_postm_2009    
		if  sample_e == 1  , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  sample_e == 1  & any_elig_halfkm == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_halfkm_postm_2009 any_elig_halfkm_e_postm_2009    
		if  sample_e == 1  & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if sample_e == 1  & any_elig_halfkm == 0 &   
 		 year < 2010;
		estadd scalar ymean = r(mean);

		estadd scalar ar=e(r2_a);
		 

	esttab using "../out/spillover_ethnic_3.tex", b(%12.4f) se(%12.3f)
	 keep( any_elig_halfkm_postm_2009 any_elig_halfkm_e_postm_2009   ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(any_elig_halfkm_postm_2009 "Any Elig*Post-2010" any_elig_halfkm_e_postm_2009 "Co-Ethnic*Post-2010" ) mtitles
		nonotes nonumber ;

*--------------------------*
* APPENDIX C1 PRE-TRENDS   *
*--------------------------;

preserve; 

* quarterly lags from 2006-2009; 
drop if year == 2005;

estimates clear;
capture file close pretrends ; 
macro drop _all            ;

local OUT   "../out/pretrends.tex" ;

local rowvars migrant num_job_orders_win comp_int 
mean_salary_d_win renew_emp_or_self_share num_jo_good_emp_pre2009_25 jo_quality ;

local rowlabs  `" "Migrant"
                 "Job Orders"
                 "Complaint Rate"
                 "Avg. Salary"
                 "Contract Renewal"
                 "Good Orders"
                 "Contract Quality" "';
                 
file open pretrends using "`OUT'", write replace text ;
file write pretrends "{" _n ;
file write pretrends "\begin{tabular}{l*{8}{c}}" _n ;
file write pretrends "\toprule" _n ;


file write pretrends 
    " Variable & Sample & F-Stat & p-value \\" _n ;
file write pretrends 
    "& (1) & (2) & (3) \\" _n ;

file write pretrends "\midrule" _n ;


local r = 1 ;
foreach v of local rowvars { ;    

gen `v'_lo = `v';
gen `v'_hi = `v';
            
    local lab : word `r' of `rowlabs';
    local lab = subinstr("`lab'","""","",.);
    file write pretrends "`lab'";
    
* all ; 
	reghdfe `v' i.elig_firm#ib20.qrtr 
	if comp_opt == 1 & qrtr <= 20, cluster(agency_id)
	 absorb(agency_id qrtr); 
 
	testparm i.elig_firm#i.qrtr;
	
	local Fstat = string(r(F),  "%9.4f") ;  
	local Pval  = string(r(p),  "%9.4f");

    file write pretrends " & All ";   
    file write pretrends " & `Fstat'" ;
    file write pretrends " & `Pval'";
    file write pretrends "\\" _n  ;


* low; 

	reghdfe `v'_lo i.elig_firm#ib20.qrtr 
	if comp_opt == 1 & qrtr <= 20 & low_score == 1, cluster(agency_id)
	 absorb(agency_id qrtr); 
 
	testparm i.elig_firm#i.qrtr;
	
	local Fstat = string(r(F),  "%9.4f") ;  
	local Pval  = string(r(p),  "%9.4f");

    file write pretrends " & Low ";   
    file write pretrends " & `Fstat'" ;
    file write pretrends " & `Pval'";
    file write pretrends "\\" _n  ;

* high; 

	reghdfe `v'_hi i.elig_firm#ib20.qrtr 
	if comp_opt == 1 & qrtr <= 20 & low_score == 0, cluster(agency_id)
	 absorb(agency_id qrtr); 
 
	testparm i.elig_firm#i.qrtr;
	
	local Fstat = string(r(F),  "%9.4f") ;  
	local Pval  = string(r(p),  "%9.4f");

    file write pretrends " & High ";   
    file write pretrends " & `Fstat'" ;
    file write pretrends " & `Pval'";  
    file write pretrends "\\\\" _n  ;
    
    drop `v'_lo;
	drop `v'_hi;

    
    local ++r;
} ;    

file write pretrends "\bottomrule" _n;
file write pretrends "\end{tabular}" _n;
file write pretrends "}" _n;
file close pretrends ;
   
restore;

*---------------------------*
* APPENDIX C3: AGENCY EXIT  * 
*---------------------------*;

** Panel A: Effects by Program Phase;

eststo clear;
	
		eststo, title("Agency Exit (6 mo)"): reghdfe firm_exit_6mo
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin );
			
		sum firm_exit_6mo if comp_opt == 1  & elig_firm == 0 & year > 2009;  
		estadd scalar ymean = r(mean);
		

		eststo, title("Agency Exit (1 yr)"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1   , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin  
		month_year##c.qs_0508_bin  );
		
		sum firm_exit_1yr if comp_opt == 1  & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);

		
		eststo, title("Agency Exit (2 yr)"): reghdfe firm_exit_2yr 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );

			
		sum firm_exit_2yr if comp_opt == 1  & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);
		
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/firm_exit_appendix_a.tex",
		 b(%12.4f) se(%12.3f)
		 keep(elig_firm_postmp_2009 elig_firm_postm          ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" ) mtitles
		nonotes nonumber ;

** Panel B: Effects by Agency Quality;

eststo clear;

		eststo, title("Agency Exit (6 mo)"): reghdfe firm_exit_6mo
		high_elig_postm_2009 low_elig_postm_2009 
		 low_postm_2009 high_postm_2009     
		if comp_opt == 1  , cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin
		     );
			
		sum firm_exit_6mo if comp_opt == 1  & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);
		

		eststo, title("Agency Exit (1 yr)"): reghdfe firm_exit_1yr 
		high_elig_postm_2009 low_elig_postm_2009 
		 low_postm_2009 high_postm_2009      
		if comp_opt == 1   , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		      );
		
		sum firm_exit_1yr if comp_opt == 1  & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);

		
		eststo, title("Agency Exit (2 yr)"): reghdfe firm_exit_2yr 
		high_elig_postm_2009 low_elig_postm_2009
		  low_postm_2009 high_postm_2009     
		if comp_opt == 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		   );
	
		sum firm_exit_2yr if comp_opt == 1  & elig_firm == 0  & year > 2009; 
		estadd scalar ymean = r(mean);
				
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/firm_exit_appendix_b.tex", b(%12.4f) se(%12.3f)
		 keep(  	high_elig_postm_2009 low_elig_postm_2009  ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber ;
		
*------------------------------*
* APPENDIX C4: TOTAL SALARIES  * 
*------------------------------*;
eststo clear;


		eststo, title("Total Salaries"): reghdfe rev_d_sinh 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1 & firm_exit_1yr != 1   , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
		
		sum rev_d_sinh if comp_opt == 1  & elig_firm == 0 &
		 year < 2010 & firm_exit_1yr != 1; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Total Salaries"): reghdfe rev_d_sinh 
		high_elig_postm_2009 low_elig_postm_2009
		  low_postm_2009 high_postm_2009   
		  
		if comp_opt == 1 & firm_exit_1yr != 1, cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin
		   );
		
		sum rev_d_sinh if comp_opt == 1  & elig_firm == 0 & year < 2010 & firm_exit_1yr != 1; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Total Salaries"): reghdfe rev_d_sinh 
 		any_elig_100ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum rev_d_sinh if comp_opt == 1  & elig_firm == 0 & year < 2010 & firm_exit_1yr != 1; 
		estadd scalar ymean = r(mean);
		
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/exit_adjustment_rev.tex", b(%12.4f) se(%12.3f) keep(     
		 	elig_firm_postmp_2009 elig_firm_postm    high_elig_postm_2009 low_elig_postm_2009  
		 	any_elig_100ft_postm_2009    ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 
		"Elig*Low*Post-2010" any_elig_100ft_postm_2009 "Any Elig*Post-2010" ) mtitles
		nonotes nonumber 	;


*-------------------------------*
* APPENDIX C5: COMPLAINT RATE   * 
*-------------------------------*;


*Panel A: Effects by Program Phase; 

eststo clear;
		
		eststo, title("Complaint Rate"): reghdfe comp_int 
		elig_firm_postmp_2009 elig_firm_postm    

		if comp_opt == 1  & migrant > 0   & firm_exit_1yr != 1 ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		month_year##c.qs_0508_bin );
		
		sum comp_int if comp_opt == 1  & migrant > 0; 
		estadd scalar ymean = r(mean);

	
		eststo, title("\% Breach"): reghdfe breach_rate
		elig_firm_postmp_2009 elig_firm_postm    
   
		if comp_opt == 1  & migrant > 0   & firm_exit_1yr != 1  & complaints > 0 & complaints != . ,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		month_year##c.qs_0508_bin );
		
		sum breach_rate if comp_opt == 1  & migrant > 0 & complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
		
		eststo, title("\% Harassment"): reghdfe harass_rate 
		elig_firm_postmp_2009 elig_firm_postm    

		if comp_opt == 1  & migrant > 0  & firm_exit_1yr != 1   & complaints > 0 & complaints != .,cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		 month_year##c.qs_0508_bin );
		
		sum harass_rate if comp_opt == 1  & migrant > 0 & complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
		
		esttab using "../out/complaints_a.tex", b(%12.3f) se(%12.3f) 
		keep( elig_firm_postmp_2009 elig_firm_postm       ) 
		
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		stats(N ymean, label("N" "Comparison Mean") fmt("%12.0f" "%12.2f")) 
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		"Elig*2012-15" ) mtitles
		nonotes nonumber;
		
*Panel B: Effects by Agency Quality; 

		eststo clear;

		eststo, title("Complaint Rate"): reghdfe comp_int
		 high_elig_postm_2009 low_elig_postm_2009 
		  low_postm_2009 high_postm_2009   
		if comp_opt == 1  & migrant > 0 & firm_exit_1yr != 1   ,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin  
		    );
		
		sum comp_int if comp_opt == 1  & migrant > 0; 
		estadd scalar ymean = r(mean);
	
		eststo, title("\% Breach"): reghdfe breach_rate 
		high_elig_postm_2009 low_elig_postm_2009 
		 low_postm_2009 high_postm_2009   
		if comp_opt == 1  & migrant > 0  & firm_exit_1yr != 1   & complaints > 0 
		& complaints != .,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin
		      );
		
		sum breach_rate if comp_opt == 1  & migrant > 0 
		& complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
	
		eststo, title("\% Harassment"): reghdfe harass_rate
		 high_elig_postm_2009 low_elig_postm_2009  
		 low_postm_2009 high_postm_2009   
		if comp_opt == 1  & migrant > 0   & firm_exit_1yr != 1  & complaints > 0 
		& complaints != .,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin 
		     );
		
		sum harass_rate if comp_opt == 1  & migrant > 0 
		& complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
	
	
		estadd scalar ar=e(r2_a);


	esttab using "../out/complaints_b.tex", b(%12.3f) se(%12.3f) 
	keep(  	 high_elig_postm_2009 low_elig_postm_2009   ) 
		
		
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		stats(N ymean, label("N" "Comparison Mean") fmt("%12.0f" "%12.2f")) 
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" 
		low_elig_postm_2009 "Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber;

* PANEL C: Effects by Agency Quality and Program Phase;

		eststo clear;
		eststo, title("Complaint Rate"): reghdfe comp_int
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		if comp_opt == 1  & migrant > 0 & firm_exit_1yr != 1   ,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin  
		    );
		
		sum comp_int if comp_opt == 1  & migrant > 0; 
		estadd scalar ymean = r(mean);
	
	
		eststo, title("\% Breach"): reghdfe breach_rate 
			high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		if comp_opt == 1  & migrant > 0  & firm_exit_1yr != 1   & complaints > 0 
		& complaints != .,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin
		      );
		
		sum breach_rate if comp_opt == 1  & migrant > 0 
		& complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
	
		eststo, title("\% Harassment"): reghdfe harass_rate
		high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm
		
		high_postmp_2009 high_postm
		low_postmp_2009 low_postm
		if comp_opt == 1  & migrant > 0   & firm_exit_1yr != 1  & complaints > 0 
		& complaints != .,cluster(agency_id) 
		absorb(agency_id  month_year##c.migrants_0508_bin 
		     );
		
		sum harass_rate if comp_opt == 1  & migrant > 0 
		& complaints > 0 & complaints != .; 
		estadd scalar ymean = r(mean);
	

		estadd scalar ar=e(r2_a);


		esttab using "../out/complaints_c.tex", b(%12.3f) se(%12.3f)
		 keep( high_elig_postmp_2009 high_elig_postm
		low_elig_postmp_2009  low_elig_postm  ) 
		
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		stats(N ymean, label("N" "Comparison Mean") fmt("%12.0f" "%12.2f")) 
			coeflabel(high_elig_postmp_2009 "Elig*High*2010-12"
		 low_elig_postmp_2009 
		"Elig*Low*2010-12" high_elig_postm "Elig*High*2012-15"
		 low_elig_postm "Elig*Low*2012-15")  mtitles
		nonotes nonumber;	
		
*------------------------------------------*
* APPENDIX C6: ROBUSTNESS TO AGENCY EXIT   * 
*------------------------------------------*;


* Panel A: Effects by Program Phase; 

eststo clear;

			
		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn 
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		
		   );
			
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0;
		estadd scalar ymean = r(mean);
	
		
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  & firm_exit_1yr != 1  , cluster(agency_id) 
		absorb(agency_id  month_year##c.qs_0508_bin
		     );
		
		sum migrant if comp_opt == 1 & elig_firm == 0 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1 & firm_exit_1yr != 1  , cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin
		    );
			
		sum num_job_orders_win if comp_opt == 1  & elig_firm == 0 & year < 2010;
		estadd scalar ymean = r(mean);

	 	estadd scalar ar=e(r2_a);

		esttab using "../out/all_exit_a.tex", b(%12.4f) se(%12.3f)
		 keep(	elig_firm_postmp_2009 elig_firm_postm          ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" ) mtitles
		nonotes nonumber 	;
	
* Panel B: Effects by Agency Quality ; 


eststo clear;


		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		high_elig_postm_2009 low_elig_postm_2009    
		low_postmp_2009 high_postmp_2009  
		
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0;
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009     
		if comp_opt == 1 & firm_exit_1yr != 1 , cluster(agency_id)
		absorb(agency_id month_year );
		  
			
		sum migrant if comp_opt == 1 & elig_firm == 0;
		estadd scalar ymean = r(mean);
		
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) 
		
		absorb(agency_id month_year##c.migrants_0508_bin );
		 
	
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);

				
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/all_exit_b.tex", b(%12.4f) se(%12.3f) 
		keep( high_elig_postm_2009 low_elig_postm_2009        ) 
		stats(N  ymean,  label("N"  "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 
		"Elig*Low*Post-2010" 
		) mtitles
		nonotes nonumber 	;


*--------------------------------------------*
* APPENDIX C7: ROBUSTNESS TO TREND CONTROLS  * 
*--------------------------------------------*;
	
* PANEL A: Quality Trend Only; 

		eststo clear;

		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.qs_0508_bin);
		
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);

		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win 
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id)
		 absorb(agency_id month_year##c.qs_0508_bin);
		
		sum mean_salary_d_win if comp_opt == 1  & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1 , cluster(agency_id)
		 absorb(agency_id month_year##c.qs_0508_bin);
		
		sum num_job_orders_win if comp_opt == 1  & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);

	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.qs_0508_bin);
		
		sum firm_exit if comp_opt == 1 & elig_firm == 0 & year > 2009; ; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/quality_trend_1.tex", b(%12.4f) se(%12.3f) keep( 
		elig_firm_postmp_2009 elig_firm_postm     ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15")
	 	mtitles
		nonotes nonumber 	;

* PANEL B: Recruitment Trend Only; 

eststo clear;

	eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 
		& year < 2010; 
		estadd scalar ymean = r(mean);

		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win 
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1  & firm_exit_1yr != 1, cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin);
		
		sum mean_salary_d_win if comp_opt == 1  & elig_firm == 0
		 & year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1 , cluster(agency_id)
		 absorb(agency_id month_year##c.migrants_0508_bin);
		
		sum num_job_orders_win if comp_opt == 1  & elig_firm == 0 
		& year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin);
		
		sum firm_exit if comp_opt == 1 & elig_firm == 0
		 & year > 2009; ; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/pre_recruit_1.tex", b(%12.4f) se(%12.3f) 
		keep(    elig_firm_postmp_2009 elig_firm_postm    ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" )
		 mtitles
		nonotes nonumber 	;
		
		
*PANEL C: No Controls; 

eststo clear;

	eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		elig_firm_postmp_2009 elig_firm_postm     
		if comp_opt == 1  , cluster(agency_id ) 
		absorb(agency_id month_year);
		
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);

		eststo, title("Avg. Salary (USD)"): reghdfe mean_salary_d_win 
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1 & firm_exit_1yr != 1, cluster(agency_id)
		 absorb(agency_id month_year);
		
		sum mean_salary_d_win if comp_opt == 1  & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		

		eststo, title("Job Orders"): reghdfe num_job_orders_win
		elig_firm_postmp_2009 elig_firm_postm 
		  
		if comp_opt == 1 , cluster(agency_id)
		 absorb(agency_id month_year);
		
		sum num_job_orders_win if comp_opt == 1  & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		elig_firm_postmp_2009 elig_firm_postm    
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year);
		
		sum firm_exit if comp_opt == 1 & elig_firm == 0 & year > 2009; ; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/no_trends_1.tex", b(%12.4f) se(%12.3f) keep(  
		elig_firm_postmp_2009 elig_firm_postm   ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15" )
	 mtitles
		nonotes nonumber 	;
		

*---------------------------------------------------------------*
* APPENDIX C8: MEAN REVERSION AND MEASURES OF AGENCY QUALITY    * 
*---------------------------------------------------------------*;

* Note, the table in this Appendix is titled: 'Robustness of Estimates to Varying Measures;
* of Pre-Program Agency Quality';

* PANEL A: 2009 Predicted Rating; 

eststo clear;

		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		high_elig_postm_2009 low_elig_postm_2009    
		low_postmp_2009 high_postmp_2009     

		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		   );
		
		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009     
		if comp_opt == 1  , cluster(agency_id)
		absorb(agency_id month_year
		   );

		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		if comp_opt == 1    , cluster(agency_id) 
		
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 
			sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ; 
		estadd scalar ymean = r(mean);
				

		eststo m3, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009 
		
		if comp_opt == 1  & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin       );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 
		& year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		eststo, title("Contract Quality"): reghdfe jo_quality 
		high_elig_postm_2009 low_elig_postm_2009    
		low_postm_2009 high_postm_2009  
		
		if comp_opt == 1   & firm_exit_1yr != 1, cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin      );
		 
		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean) ;
		
		esttab * using "../out/combined_het_ps.tex", b(%12.4f) se(%12.3f) 
		keep(high_elig_postm_2009 low_elig_postm_2009  ) 
		stats(N  ymean,  label("N" "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(high_elig_postm_2009 "Elig*High*Post-2010" low_elig_postm_2009 
		"Elig*Low*Post-2010"	) 
		 mtitles
		nonotes nonumber ;
		
* PANEL B: 2009 Predicted Rating; 

eststo clear;

		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009     

		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		   );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009     
		if comp_opt == 1  , cluster(agency_id)
		absorb(agency_id month_year
		   );
		
		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
			
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009  
		if comp_opt == 1   , cluster(agency_id) 
		
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 
	
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009  
		
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 

		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ; 
		estadd scalar ymean = r(mean);
				
	

		eststo m3, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009 
		
		if comp_opt == 1   & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin       );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 
		& year < 2010 ; 
		estadd scalar ymean = r(mean);

		eststo, title("Contract Quality"): reghdfe jo_quality 
		h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009    
		l_qs_09_postm_2009 h_qs_09_postm_2009  
		
		if comp_opt == 1   & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin      );
		 

		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean) ;

		esttab * using "../out/combined_het_qs_09.tex", b(%12.4f) se(%12.3f) 
		keep(h_qs_09_elig_postm_2009 l_qs_09_elig_postm_2009   ) 
		stats(N  ymean,  label("N"  "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(h_qs_09_elig_postm_2009 "Elig*High*Post-2010" l_qs_09_elig_postm_2009 
		"Elig*Low*Post-2010"	) 
		 mtitles
		nonotes nonumber ;


* PANEL C:  07-09 quantitative score;

eststo clear;

		eststo, title("Quant Score"): reghdfe partial_qual_marks_mn
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    

		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0709_bin 
		   );
		

		sum partial_qual_marks_mn if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
	
		eststo, title("Migrants"): reghdfe migrant
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    
		l_qs_0709_postm_2009 h_qs_0709_postm_2009     
		if comp_opt == 1  , cluster(agency_id)
		absorb(agency_id month_year
		   );
		  

		sum migrant if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Job Orders"): reghdfe num_job_orders_win
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    
		l_qs_0709_postm_2009 h_qs_0709_postm_2009  
		if comp_opt == 1   , cluster(agency_id) 
		
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 
		sum num_job_orders_win if comp_opt == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    
		l_qs_0709_postm_2009 h_qs_0709_postm_2009  
		
		if comp_opt == 1  , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin
		  );
		 

		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ; 
		estadd scalar ymean = r(mean);
				
			
		eststo m3, title("Good Orders"): reghdfe num_jo_good_emp_pre2009_25 
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    
		l_qs_0709_postm_2009 h_qs_0709_postm_2009 
		
		if comp_opt == 1  & firm_exit_1yr != 1  , cluster(agency_id) absorb(agency_id 
		month_year##c.migrants_0508_bin       );
		
			
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 
		& year < 2010 ; 
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Contract Quality"): reghdfe jo_quality 
		h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009    
		l_qs_0709_postm_2009 h_qs_0709_postm_2009  
		
		if comp_opt == 1   & firm_exit_1yr != 1 , cluster(agency_id) absorb(agency_id
		 month_year##c.migrants_0508_bin      );
		 	
		
		sum jo_quality if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean) ;
		

		esttab * using "../out/combined_het_qs_0709.tex", b(%12.4f) se(%12.3f) 
		keep(     	h_qs_0709_elig_postm_2009 l_qs_0709_elig_postm_2009   ) 
		stats(N  ymean,  label("N"  "Comparison Mean" ) fmt("%12.0f"  "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(h_qs_0709_elig_postm_2009 "Elig*High*Post-2010" l_qs_0709_elig_postm_2009 
		"Elig*Low*Post-2010"	) 
		 mtitles
		nonotes nonumber ;

*--------------------------------------------------*
* APPENDIX C9: ROBUSTNESS OF SPILLOVER EFFECTS     * 
*--------------------------------------------------*;

** PANEL A---- 100ft ;

		eststo clear;
					
		eststo, title("Migrants"): reghdfe migrant
		any_elig_100ft_postm_2009     
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_100ft_postm_2009     
		if comp_opt == 1 & elig_firm == 0, clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  comp_opt == 1 & elig_firm == 0 & 
		any_elig_100ft_postm_2009 == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_100ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_100ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & any_elig_100ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);

		estadd scalar ar=e(r2_a);
		 
	esttab using "../out/spillover_robust_1.tex", nocon b(%12.4f) se(%12.3f) keep(  
	any_elig_100ft_postm_2009  
		   ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label 
		coeflabel(any_elig_100ft_postm_2009 "Any Elig*Post-2010"  ) mtitles
		nonotes nonumber  		;

** PANEL B ---- 500ft ;

		eststo clear;
						
		eststo, title("Migrants"): reghdfe migrant
		any_elig_500ft_postm_2009     
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  comp_opt == 1 & elig_firm == 0 & any_elig_500ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_500ft_postm_2009     
		if comp_opt == 1 & elig_firm == 0, clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  comp_opt == 1 & elig_firm == 0 & 
		any_elig_500ft_postm_2009 == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_500ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  comp_opt == 1 & elig_firm == 0 & any_elig_500ft == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_500ft_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & any_elig_500ft == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);


		estadd scalar ar=e(r2_a);
		 


	esttab using "../out/spillover_robust_2.tex", nocon b(%12.4f) se(%12.3f) keep( 
	any_elig_500ft_postm_2009   
		   ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label 
		coeflabel(any_elig_500ft_postm_2009 "Any Elig*Post-2010"  ) mtitles
		nonotes nonumber  ;

** PANEL C  --- 0.5 km ;

		eststo clear;
		
		eststo, title("Migrants"): reghdfe migrant
		any_elig_halfkm_postm_2009     
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum migrant if  comp_opt == 1 & elig_firm == 0 & any_elig_halfkm == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);
		
	
		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		any_elig_halfkm_postm_2009     
		if comp_opt == 1 & elig_firm == 0, clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin 
		 month_year##c.qs_0508_bin);
		
		sum firm_exit_1yr if  comp_opt == 1 & elig_firm == 0 & 
		any_elig_halfkm_postm_2009 == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job orders"): reghdfe num_job_orders_win
		 any_elig_halfkm_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_job_orders_win  if  comp_opt == 1 & elig_firm == 0 & any_elig_halfkm == 0 &   
  		year < 2010 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Good orders"): reghdfe num_jo_good_emp_pre2009_25
		 any_elig_halfkm_postm_2009    
		if  comp_opt == 1 & elig_firm == 0 & firm_exit_1yr != 1 , clust(agency_vil_id) 
		absorb(agency_id  year##agency_vil_id  month_year##c.migrants_0508_bin
		  month_year##c.qs_0508_bin );
		
		sum num_jo_good_emp_pre2009_25 if comp_opt == 1 & elig_firm == 0 & any_elig_halfkm == 0 &   
 		 year < 2010 ;
		estadd scalar ymean = r(mean);


		estadd scalar ar=e(r2_a);
		 

	esttab using "../out/spillover_robust_3.tex", b(%12.4f) se(%12.3f)
	 keep(any_elig_halfkm_postm_2009  ) 
		stats(N ymean, label("N" "Comparison Mean" ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(any_elig_halfkm_postm_2009 "Any Elig*Post-2010"  ) mtitles
		nonotes nonumber ;


*---------------------------------------------------------------*
* APPENDIX C11: PROGRAM EFFECTS WITH ALTERNATIVE SAMPLES   * 
*---------------------------------------------------------------*;

* Panel A : Recruited 45-155 Migrants in 2009; 

eststo clear;

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm  

		if comp_opt == 1  , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_opt == 1   , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum num_job_orders if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postmp_2009 elig_firm_postm  
   
		if comp_opt == 1  , cluster(agency_id) absorb(agency_id month_year##c.qs_0508_bin  );
		
		sum migrant if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
			
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/alt_count_1.tex", b(%12.4f) se(%12.3f) 
		keep( elig_firm_postmp_2009 elig_firm_postm ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;


* Panel B : Recruited 25-175 Migrants in 2009; 

eststo clear;

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
	    elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_25_175 == 1  , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum firm_exit_1yr if comp_25_175 == 1 & elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_25_175 == 1   , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum num_job_orders if comp_25_175 == 1 & elig_firm == 0 & year < 2010 ; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postmp_2009 elig_firm_postm  
   
		if comp_25_175 == 1  , cluster(agency_id) absorb(agency_id   month_year##c.qs_0508_bin  );
		
		sum migrant if comp_25_175 == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/alt_count_2.tex", b(%12.4f) se(%12.3f) keep( 
		 		elig_firm_postmp_2009 elig_firm_postm  ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber 	;
		
* Panel C: All Agencies ; 

eststo clear;

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm  
  
	   , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum firm_exit_1yr if  elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		 , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum num_job_orders if  elig_firm == 0 & year < 2010  ; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant
		elig_firm_postmp_2009 elig_firm_postm  
   
		, cluster(agency_id) absorb(agency_id  month_year##c.qs_0508_bin  );
		
		sum migrant if elig_firm == 0 & year < 2010  ; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/alt_count_3.tex", b(%12.4f) se(%12.3f) 
		keep( elig_firm_postmp_2009 elig_firm_postm  ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
	
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber 	;
		
*-------------------------------------------------------*
* APPENDIX C12: ROBUSTNESS OF ESTIMATES TO FBR REFORM   * 
*-------------------------------------------------------*;

* Panel A, Main Specification ;

eststo clear;

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm  

		if comp_opt == 1  , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_opt == 1   , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum num_job_orders if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant_t975
		elig_firm_postmp_2009 elig_firm_postm  
   
		if comp_opt == 1  , cluster(agency_id) absorb(agency_id month_year##c.qs_0508_bin  );
		
		sum migrant_t975 if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/fbr_robust_1.tex", b(%12.4f) se(%12.3f) keep( 
				elig_firm_postmp_2009 elig_firm_postm  
		  ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;

* Panel B: Pre-July 2013 data; 

eststo clear;

		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm  

		if comp_opt == 1 & month_year < 103  , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_opt == 1  & month_year < 103 , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin month_year##c.qs_0508_bin );
			
		sum num_job_orders if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant_t975
		elig_firm_postmp_2009 elig_firm_postm  
   
		if comp_opt == 1 & month_year < 103 , cluster(agency_id) absorb(agency_id month_year##c.qs_0508_bin  );
		
		sum migrant_t975 if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/fbr_robust_2.tex", b(%12.4f) se(%12.3f) keep( 
		elig_firm_postmp_2009 elig_firm_postm  
		  ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber ;		


* Panel C: Domestic Workers Trend; 

eststo clear;


		eststo, title("Agency Exit"): reghdfe firm_exit_1yr 
		elig_firm_postmp_2009 elig_firm_postm  

		if comp_opt == 1   , cluster(agency_id) 
		absorb(agency_id month_year##c.migrants_0508_bin 
		month_year##c.dom_share_pre );
		
		sum firm_exit_1yr if comp_opt == 1 & elig_firm == 0 & year > 2009 ;
		estadd scalar ymean = r(mean);
		
		
		eststo, title("Job Orders"): reghdfe num_job_orders_win 
		elig_firm_postmp_2009 elig_firm_postm  
  
		if comp_opt == 1  , cluster(agency_id) absorb(agency_id month_year##c.migrants_0508_bin 
		month_year##c.dom_share_pre );
			
		sum num_job_orders if comp_opt == 1 & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
				
		eststo, title("Migrants"): reghdfe migrant_t975
		elig_firm_postmp_2009 elig_firm_postm  
   
		if comp_opt == 1 , cluster(agency_id) absorb(agency_id month_year##c.dom_share_pre  );
		
		sum migrant_t975 if comp_opt == 1  & elig_firm == 0 & year < 2010; 
		estadd scalar ymean = r(mean);
		
	 	estadd scalar ar=e(r2_a);

		esttab using "../out/fbr_robust_3.tex", b(%12.4f) se(%12.3f) keep( 
		elig_firm_postmp_2009 elig_firm_postm  
		  ) 
		stats(N ymean, label("N" "Comparison Mean"  ) fmt("%12.0f" "%12.2f")) 
		starlevels(* 0.10 ** 0.05 *** 0.01) booktabs replace label
		coeflabel(elig_firm_postmp_2009 "Elig*2010-12" elig_firm_postm
		 "Elig*2012-15") mtitles
		nonotes nonumber 	;

		




